<?php
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
//require_once '../maths/tool_maths.php';

class Tool_pear_graph{

  public $width=900;
  public $height=600;

  public $array_array_x=array();
  public $array_array_y=array();

  public $max_x;
  public $max_y;

  public $min_x;
  public $min_y;

  public $interval_x;
  public $interval_y;

  public $plot_title=array();
  public $plot_color=array();

  public $title=array();

  public function __construct($_width=900,$_height=400){
    $this->width=$_width;
    $this->height=$_height;
  }

  public function __add_array_x($_array_x){
    $this->array_array_x[]=$_array_x;
  }
  public function __add_array_y($_array_y){
    $this->array_array_y[]=$_array_y;
  }

  public function __set_width($_width){
    $this->width=$_width;
  }
  public function __set_height($_height){
    $this->height=$_height;
  }

  public function __set_max_x($_max_x){
    $this->max_x=$_max_x;
  }
  public function __set_min_x($_min_x){
    $this->min_x=$_min_x;
  }
  public function __set_max_y($_max_y){
    $this->max_y=$_max_y;
  }
  public function __set_min_y($_min_y){
    $this->min_y=$_min_y;
  }

  public function __set_interval_x($_i_x){
    $this->interval_x = $_i_x;
  }
  public function __set_interval_y($_i_y){
    $this->interval_y = $_i_y;
  }

  public function __add_title($_title){
    $this->title=$_title;
  }
  public function __add_plot_title($_title,$_default=null){
    if($_default==null) $this->plot_title[]=$_title;
    else $this->plot_title[$_default]=$_title;
  }

  public function __add_plot_color($_color){
    $this->plot_color[]=$_color;
  }

  public function __get_basic_canvas(){
    $canvas = & Image_Canvas::factory('svg', array('width' => $this->width,
                                                   'height' => $this->height,
                                                   'encoding'=>'UTF-8'));
    return $canvas;
  } 

  public function __get_all_dataset(){
    $Dataset=array();
    foreach($this->array_array_x as $id1=>$array_x){
      $Dataset[$id1] =& Image_Graph::factory('dataset');
      foreach($array_x as $id2=>$x){
        if(isset($this->plot_title[$id1])){
          $Dataset[$id1]->addPoint($x, $this->array_array_y[$id1][$id2],$this->plot_title[$id1]); 
        }
        else{
          $Dataset[$id1]->addPoint($x, $this->array_array_y[$id1][$id2]);
        }
      }
    }
    return $Dataset;
  }

  public function __get_info_axis($Dataset){
    foreach($Dataset as $data){
      $amin_y[]=ceil($data->minimumY());
      $amax_y[]=floor($data->maximumY());
      $amin_x[]=ceil($data->minimumX());
      $amax_x[]=floor($data->maximumX());
    }

    $min_y=min($amin_y); $min_x=min($amin_x);
    $max_y=max($amax_y); $max_x=max($amax_x);

    $step_y=tool_maths::get_ten(abs($max_y-$min_y))/10;
    $step_x=tool_maths::get_ten(abs($max_x-$min_x))/10;
    
    $min_x=tool_maths::ceil_with_step($min_x,$step_x);
    $min_y=tool_maths::ceil_with_step($min_y,$step_y);
    $max_x=tool_maths::floor_with_step($max_x,$step_x);
    $max_y=tool_maths::floor_with_step($max_y,$step_y);

    return array("x"=>array("min"=>$min_x,"max"=>$max_x,"step"=>$step_x),
                 "y"=>array("min"=>$min_y,"max"=>$max_y,"step"=>$step_y));
  }

  public function scatter01(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

//    $GridX =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_X);
//    $GridX->setFillStyle(Image_Graph::factory('gradient',
//                          array(IMAGE_GRAPH_GRAD_RADIAL, 'white','lightgrey')));
//    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);
    $Dataset=$this->__get_all_dataset();

    /*
     * info start here
     */
    $info=$this->__get_info_axis($Dataset);
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->forceMaximum($info["x"]["max"]+1);  
    $Axis->forceMinimum($info["x"]["min"]-1);  
    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/4);  

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    $Axis->forceMaximum($info["y"]["max"]+1);  
    $Axis->forceMinimum($info["y"]["min"]-1);  
    /*
     * info end here
     */

    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i]));
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Value',IMAGE_GRAPH_POINT_ID);
      $Marker[$i]->setFillColor(tool_color::$array_color[$i]);
      $Marker[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i]->setSize(3);
      $Plot[$i]->setMarker($Marker[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }


  public function scatter02(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
//          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $Dataset=$this->__get_all_dataset();

    /*
     * info start here
     */
    $info=$this->__get_info_axis($Dataset);
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->forceMaximum($info["x"]["max"]+1);  
    $Axis->forceMinimum($info["x"]["min"]-1);  
    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/4);  

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    $Axis->forceMaximum($info["y"]["max"]+1);  
    $Axis->forceMinimum($info["y"]["min"]-1);  
    /*
     * info end here
     */

    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i]));
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      $Marker[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i]->setSize(5);
      $Plot[$i]->setMarker($Marker[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }



  public function plot01(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array('rapport secondes par caractères',
                                      12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Dataset=$this->__get_all_dataset();
    $info=$this->__get_info_axis($Dataset);

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->forceMaximum($info["x"]["max"]);  
    $Axis->forceMinimum($info["x"]["min"]);  
    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/4);  

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    $Axis->forceMaximum($info["y"]["max"]);  
    $Axis->forceMinimum($info["y"]["min"]);  
    if($info["y"]["step"]>1)$Axis->setLabelInterval($info["y"]["step"]/4);  
//    $Plot1 =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset1));
//    $Plot1 =& $Plotarea->addNew('line', array(&$Dataset1));
    $Plot1 =& $Plotarea->addNew('line', array(&$Dataset[0]));
    $Marker1 =& Image_Graph::factory('Image_Graph_Marker_Circle');
    $Marker1->setFillColor('#DDDDDD');
    $Marker1->setLineColor('black');
    $Marker1->setSize(3);
    $Plot1->setMarker($Marker1);
    //$Plot1->setTitle('Introvert');
    //$Graph->done();
    return $Graph;
  }

  public function plot02(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array('rapport secondes par caractères',
                                      12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Dataset=$this->__get_all_dataset();
    $info=$this->__get_info_axis($Dataset);

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->forceMaximum($info["x"]["max"]);  
    $Axis->forceMinimum($info["x"]["min"]);  
    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/2);  

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    $Axis->forceMaximum($info["y"]["max"]);  
    $Axis->forceMinimum($info["y"]["min"]);  
    if($info["y"]["step"]>1)$Axis->setLabelInterval($info["y"]["step"]/4);  
//    $Plot1 =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset1));
//    $Plot1 =& $Plotarea->addNew('line', array(&$Dataset1));
    for($i=0;$i<count($Dataset);$i++){
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      $Marker[$i]->setFillColor("#DDDDDD");
      $Marker[$i]->setLineColor($this->array_color[$i]);
      $Marker[$i]->setSize(4);
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setMarker($Marker[$i]);
      $Plot[$i]->setLineColor($this->array_color[$i]);
    }

    return $Graph;
  }

  public function plot_log_log01(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis_log','axis_log')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $AxisY =& $Plotarea->getAxis('y');
    $AxisY->setLabelInterval(array(0,1,2,3,4,5,10,20,30,40,50,100,200,400,500,1000,10000,20000,30000)); 
    $AxisY =& $Plotarea->getAxis('x');
    $AxisY->setLabelInterval(array(0,1,2,3,4,5,10,20,50,100,200,500,1000,10000,20000,30000)); 

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->setAxisIntersection(0);
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot_line_regression(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis_log','axis_log')),
//          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Fit_Line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot_line_regression2(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

//    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);
    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Fit_Line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      $Marker[$i]->setFillColor("#DDDDDD");
      $Marker[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i]->setSize(4);
      $Plot[$i]->setMarker($Marker[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot_dot_regression(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea',array('axis_log','axis_log')),
//          $Plotarea = Image_Graph::factory('plotarea',array('axis','axis')),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i]));
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      $Marker[$i]->setFillColor("#DDDDDD");
      $Marker[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i]->setSize(2);
      $Plot[$i]->setMarker($Marker[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot03(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $GridX =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_X);
    $GridX->setFillStyle(Image_Graph::factory('gradient',
                          array(IMAGE_GRAPH_GRAD_RADIAL, 'white','lightgrey')));
    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Dataset=$this->__get_all_dataset();
/*
    $info=$this->__get_info_axis($Dataset);

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $Axis->forceMaximum($info["x"]["max"]);  
    $Axis->forceMinimum($info["x"]["min"]);  
    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/2);  
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    $Axis->forceMaximum($info["y"]["max"]);  
    $Axis->forceMinimum($info["y"]["min"]);  
    if($info["y"]["step"]>1)$Axis->setLabelInterval($info["y"]["step"]/4);
*/
//    $Plot1 =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset1));
//    $Plot1 =& $Plotarea->addNew('line', array(&$Dataset1));
    for($i=0;$i<count($Dataset);$i++){
      //$Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      //$Marker[$i]->setFillColor("#DDDDDD");
      //$Marker[$i]->setLineColor($this->array_color[$i]);
      //$Marker[$i]->setSize(2);
     // $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Smoothed_Area', array(&$Dataset[$i]));
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
//  Smoothed_
      //$Plot[$i]->setFillColor(tool_color::$array_color[$i].'@0.1');
      //$Plot[$i]->setMarker($Marker[$i]);
      if(isset($this->plot_color[$i]))
        $Plot[$i]->setLineColor($this->plot_color[$i]);
      else
        $Plot[$i]->setLineColor(tool_color::$array_color[$i]);

      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot04(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Dataset=$this->__get_all_dataset();


    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$Dataset[$i]));
      $Plot[$i]->setFillColor(tool_color::$array_color[$i].'@0.2');
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

  public function plot05(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('Image_Graph_Legend'),
          85
        ),
        8
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $GridX =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_X);
    $GridX->setFillStyle(Image_Graph::factory('gradient',
                          array(IMAGE_GRAPH_GRAD_RADIAL, 'white','lightgrey')));
    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Dataset=$this->__get_all_dataset();

    $info=$this->__get_info_axis($Dataset);
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
//    $Axis->setTitle('axe x',array("size"=>10));
//    $Axis->forceMaximum($info["x"]["max"]);  
//    $Axis->forceMinimum($info["x"]["min"]);  
    if(isset($this->max_x)) $Axis->forceMaximum($this->max_x);
    if(isset($this->min_x)) $Axis->forceMinimum($this->min_x);
//    if($info["x"]["step"]>1) $Axis->setLabelInterval($info["x"]["step"]/2);  
    $Axis->setLabelInterval(1);  
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
//    $Axis->setAxisIntersection(0);
    if(isset($this->max_y)){
      $Axis->forceMaximum($this->max_y);
    }
//    $Axis->setTitle('axe y','vertical');
//    $Axis->setTitle('axe y',array("size"=>13));
//    $Axis->forceMinimum($info["y"]["min"]);  
//    if($info["y"]["step"]>1)$Axis->setLabelInterval($info["y"]["step"]/4);


    for($i=0;$i<count($Dataset);$i++){
//      $Dataset[$i]->setName($i);
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$Dataset[$i]));
      $Plot[$i]->setFillColor(tool_color::$array_color[$i].'@0.2');
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

//    $leg=&$Plotarea->addNew('legend');
//    $leg->setFontSize(10);
//    $leg->setAlignment(0);
//    $leg->setFontAngle("90");
    return $Graph;
  }

  public function plot06(){
    //create a canvias
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array("",8)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('Image_Graph_Legend'),
          85
        ),
        8
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $GridX =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_X);

    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Dataset=$this->__get_all_dataset();

    $info=$this->__get_info_axis($Dataset);
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    if(isset($this->max_x)) $Axis->forceMaximum($this->max_x);
    if(isset($this->min_x)) $Axis->forceMinimum($this->min_x);
    $Axis->setLabelInterval(1);  
    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
//    $Axis->setLabelInterval(1);  
    if(isset($this->max_y)) $Axis->forceMaximum($this->max_y);
//    $Axis->setLabelOption("showtext",false);

    for($i=0;$i<2;$i++){
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$Dataset[$i]));
      $Plot[$i]->setFillColor(tool_color::$array_color[$i].'@0.2');
      $Plot[$i]->setLineColor("#555555");
      $Marker[$i] =& Image_Graph::factory('Image_Graph_Marker_Circle');
      $Marker[$i]->setFillColor("#DDDDDD");
      $Marker[$i]->setLineColor(tool_color::$array_color[$i]);
      $Marker[$i]->setSize(3);
      $Plot[$i]->setMarker($Marker[$i]);
    }

    for($i=2;$i<count($Dataset);$i++){
      
      $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Area', array(&$Dataset[$i]));
      $Plot[$i]->setFillColor(tool_color::$array_color[$i].'@0.6');
//      $Plot[$i]->setLineColor(tool_color::$array_color[$i].'@1');
      $Plot[$i]->setLineColor('#2222FF@1');
      $Plot[$i]->setTitle("bloc".($i-2));
    }
    return $Graph;
  }

  public function line01(){
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $GridX =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_X);
    $GridX->setFillStyle(Image_Graph::factory('gradient',
                          array(IMAGE_GRAPH_GRAD_RADIAL, 'white','lightgrey')));
    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      if(isset($this->plot_color[$i]))
        $Plot[$i]->setLineColor($this->plot_color[$i]);
      else
        $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }


  public function line02(){
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        
    $Plotarea->addNew('line_grid',false,IMAGE_GRAPH_AXIS_Y);

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    if(isset($this->max_x)) $Axis->forceMaximum($this->max_x);
    if(isset($this->min_x)) $Axis->forceMinimum($this->min_x);
    $Axis->setLabelInterval(1);  

    $Axis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $Axis->setAxisIntersection(0);
    if(isset($this->max_y)){
      $Axis->forceMaximum($this->max_y);
    }

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);$i++){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor(tool_color::$array_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }


  public function line_color00(){
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);++$i){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor($this->plot_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }


  public function line_color01(){
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          90
        ),
        5
      )
    );
    $Legend->setPlotarea($Plotarea);        


    $AxisY =& $Plotarea->getAxis('y');
    $interY = array_map("round_log",array(1,2,3,4,5,10,20,30,40,50,100,200,400,500));
    $AxisY->setLabelInterval($interY); 
    $AxisY =& $Plotarea->getAxis('x');
    $interX = array_map("round_log",array(1,2,3,4,5,10,20,50,100,200,500,1000));
    $AxisY->setLabelInterval($interX); 

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);++$i){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor($this->plot_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }


  public function line_color(){
    $Canvas=$this->__get_basic_canvas();
    $Graph =& Image_Graph::factory('graph', $Canvas);

    $Graph->add(
      Image_Graph::vertical(
        Image_Graph::factory('title', array($this->title,12)),
        Image_Graph::vertical(
          $Plotarea = Image_Graph::factory('plotarea','axis','axis'),
          $Legend = Image_Graph::factory('legend'),
          100
        ),
        1
      )
    );

    $Legend->setPlotarea($Plotarea);        

    $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $AxisY->setAxisIntersection(0);
    if(isset($this->max_y)) $AxisY->forceMaximum($this->max_y);
    if(isset($this->min_y)) $AxisY->forceMinimum($this->min_y);

    $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    if(isset($this->interval_x)) $AxisX->setLabelInterval($this->interval_x);

    $Dataset=$this->__get_all_dataset();
    for($i=0;$i<count($Dataset);++$i){
      $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i]));
      $Plot[$i]->setLineColor($this->plot_color[$i]);
      if(isset($this->plot_title[$i])){
        $Plot[$i]->setTitle($this->plot_title[$i]);
      }
    }

    return $Graph;
  }

}

?>
